package com.haitaoit.chengquan.module.center_service;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.base.ExitApplication;
import com.haitaoit.chengquan.module.center.activity.info.MyForumActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyMessageActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyMoneyActivity;
import com.haitaoit.chengquan.module.center.activity.yuyue.YuyueEvaluateActivity;
import com.haitaoit.chengquan.module.center.model.UserInfoModel;
import com.haitaoit.chengquan.module.center_service.activity.ServiceEvaluateActivity;
import com.haitaoit.chengquan.module.center_service.activity.ServiceInfoActivity;
import com.haitaoit.chengquan.module.center_service.activity.ServiceRecruitActivity;
import com.haitaoit.chengquan.module.center_service.activity.service_order.ServiceFuwuActivity;
import com.haitaoit.chengquan.module.center_service.activity.service_order.ServiceFuwuDetailActivity;
import com.haitaoit.chengquan.module.center_service.activity.xuqiu_order.ServiceXuqiuActivity;
import com.haitaoit.chengquan.module.center_service.adapter.service_order.ServiceFuwuAdapter;
import com.haitaoit.chengquan.module.center_service.model.ServiceFuwuModel;
import com.haitaoit.chengquan.module.login.LoginActivity;
import com.haitaoit.chengquan.utils.Constant;
import com.haitaoit.chengquan.utils.DateTimeUtil;
import com.haitaoit.chengquan.utils.DialogUtil;
import com.haitaoit.chengquan.utils.GetSign;
import com.haitaoit.chengquan.utils.HttpUtilsSingle;
import com.haitaoit.chengquan.utils.NameValuePairSign;
import com.haitaoit.chengquan.utils.PreferenceUtils;
import com.haitaoit.chengquan.utils.ToastUtils;
import com.haitaoit.chengquan.view.CircleImageView;
import com.haitaoit.chengquan.view.MyListView;
import com.haitaoit.chengquan.view.PullToRefreshBase;
import com.haitaoit.chengquan.view.PullToRefreshScrollView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class CenterServiceFragment extends Fragment implements PullToRefreshBase.OnRefreshListener<ScrollView> {
    @ViewInject(R.id.pullrefreshscrollview)
    PullToRefreshScrollView pullrefreshscrollview;

    private ScrollView mScrollView;
    private LinearLayout null_information_layout;
    private MyListView listView;
    private CircleImageView center_img;
    private ImageView center_message;
    private TextView service_balance, service_name;

    private boolean isFrist = true;
    private int page = 1;

    //    private CenterServiceAdapter adapter;
    private ServiceFuwuAdapter adapter;
    private Dialog dlg;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.pullrefreshscollview, null);
        ViewUtils.inject(this, v);


        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_service_center, null);
        null_information_layout = (LinearLayout) view.findViewById(R.id.null_information_layout);
        listView = (MyListView) view.findViewById(R.id.scrollview_listview);

        center_img = (CircleImageView) view.findViewById(R.id.center_img);
        center_message = (ImageView) view.findViewById(R.id.center_message);
        service_name = (TextView) view.findViewById(R.id.service_name);
        service_balance = (TextView) view.findViewById(R.id.service_balance);

        view.findViewById(R.id.center_img).setOnClickListener(listener);
        view.findViewById(R.id.center_message).setOnClickListener(listener);
        view.findViewById(R.id.service_xiuqiu_dd).setOnClickListener(listener);
        view.findViewById(R.id.service_fuwu_dd).setOnClickListener(listener);
        view.findViewById(R.id.service_eva).setOnClickListener(listener);
        view.findViewById(R.id.service_zhaopin).setOnClickListener(listener);
        view.findViewById(R.id.service_money).setOnClickListener(listener);
        view.findViewById(R.id.center_group_gl).setOnClickListener(listener);

        pullrefreshscrollview.setPullLoadEnabled(false);
        pullrefreshscrollview.setPullRefreshEnabled(false);
        pullrefreshscrollview.setOnRefreshListener(this);
        pullrefreshscrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        mScrollView = pullrefreshscrollview.getRefreshableView();
        mScrollView.setFillViewport(true);
        mScrollView.setVerticalScrollBarEnabled(false);
        mScrollView.addView(view);

        adapter = new ServiceFuwuAdapter(getActivity());
        adapter.setTitle_type("1");
        adapter.setBackCall(backCall);
        listView.setAdapter(adapter);
        return v;
    }

    @Override
    public void onResume() {
        if (PreferenceUtils.getPrefString("user_id", "").equals("")) {
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            intent.putExtra("tag", "2");
            startActivity(intent);
        } else {
            if ("2".equals(PreferenceUtils.getPrefString("account_type", ""))) {
                httpGetUserInfo(Constant.Getgr_user_model);
            } else if ("3".equals(PreferenceUtils.getPrefString("account_type", ""))) {
                httpGetUserInfo(Constant.Getqy_user_model);
            }
        }
        mScrollView.smoothScrollTo(0, 0);
        super.onResume();
    }

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            switch (v.getId()) {
                case R.id.center_message:// 消息
                    intent.setClass(getActivity(), MyMessageActivity.class);
                    startActivity(intent);
                    break;
                case R.id.center_img:// 头像
                    intent.setClass(getActivity(), ServiceInfoActivity.class);
                    startActivity(intent);
                    break;
                case R.id.service_xiuqiu_dd:// 需求订单
                    intent.setClass(getActivity(), ServiceXuqiuActivity.class);
                    startActivity(intent);
                    break;
                case R.id.service_fuwu_dd:// 服务订单
                    intent.setClass(getActivity(), ServiceFuwuActivity.class);
                    startActivity(intent);
                    break;
                case R.id.service_eva:// 我的评价
                    intent.setClass(getActivity(), ServiceEvaluateActivity.class);
                    startActivity(intent);
                    break;
                case R.id.service_zhaopin:// 我的招聘
                    intent.setClass(getActivity(), ServiceRecruitActivity.class);
                    startActivity(intent);
                    break;
                case R.id.service_money:// 我的钱包
                    intent.setClass(getActivity(), MyMoneyActivity.class);
                    startActivity(intent);
                    break;
                case R.id.center_group_gl:
                    intent.setClass(getActivity(), MyForumActivity.class);
                    startActivity(intent);
                    break;
            }
        }
    };

    BackCall backCall = new BackCall() {
        @Override
        public void deal(int which, Object... obj) {
            Intent intent = new Intent();
            final int position = (Integer) obj[0];
            switch (which) {
                case R.id.fuwu_itemll:// 详情
                case R.id.fuwu_check_eva:// 查看评价
//                case R.id.scrollview_listview:
                    intent.setClass(getActivity(), ServiceFuwuDetailActivity.class);
                    intent.putExtra("title_type", "1");
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    startActivity(intent);
                    break;
                case R.id.fuwu_to_eva:// 评价需求商
                    intent.setClass(getActivity(), YuyueEvaluateActivity.class);
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    intent.putExtra("type", "2");
                    intent.putExtra("myimage_uri", adapter.getList().get(position).getTitile_img());
                    startActivity(intent);
                    break;
                case R.id.confirm_complete:// 服务完成
                    dlg = DialogUtil.showInfoDialog1(getActivity(), "提示",
                            "您确定该订单服务已完成吗？", "确定", "还没有", new BackCall() {
                                public void deal(int which, Object... obj) {
                                    switch (which) {
                                        case R.id.confirm:// 确定
                                            httpGetmer_service_complete_order(adapter.getList().get(position).getOrder_no());
                                            break;
                                    }
                                    super.deal(which);
                                }
                            });
                    dlg.setCanceledOnTouchOutside(true);
                    dlg.show();
                    break;
                case R.id.detele_fuwu:// 删除订单
                    dlg = DialogUtil.showInfoDialog1(getActivity(), "提示", "您确定要删除该服务订单吗？", "确定", "取消", new BackCall() {
                        public void deal(int which, Object... obj) {
                            switch (which) {
                                case R.id.confirm:// 确定
                                    httpGetdel_order(adapter.getList().get(position).getOrder_no());
                                    break;
                            }
                            super.deal(which);
                        }
                    });
                    dlg.setCanceledOnTouchOutside(true);
                    dlg.show();
                    break;
                case R.id.fuwu_submit_order:// 确认订单
                    dlg = DialogUtil.showInfoDialog1(getActivity(), "提示", "您要确认订单吗？", "确定", "取消", new BackCall() {
                        public void deal(int which, Object... obj) {
                            switch (which) {
                                case R.id.confirm:// 确定
                                    httpGetmer_service_confirm_order(adapter.getList().get(position).getOrder_no());
                                    break;
                            }
                            super.deal(which);
                        }
                    });
                    dlg.setCanceledOnTouchOutside(true);
                    dlg.show();
                    break;
                case R.id.fuwu_update_order:// 修改订单
                    dlg = DialogUtil.ShowUpdateOrderDialog(getActivity(), new BackCall() {
                        @Override
                        public void deal(int which, Object... obj) {
                            String price = (String) obj[0];
                            switch (which) {
                                case R.id.submit_price:
                                    httpGetmer_service_update_order_amount(adapter.getList().get(position).getOrder_no(), price);
                                    break;
                            }
                            super.deal(which, obj);
                        }
                    });
                    dlg.setCanceledOnTouchOutside(true);
                    dlg.show();

                    DisplayMetrics metric = new DisplayMetrics();
                    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
                    int width = metric.widthPixels; // 屏幕宽度（像素）
                    WindowManager.LayoutParams params = dlg.getWindow().getAttributes();
                    params.width = width;
                    params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
                    dlg.getWindow().setAttributes(params);
                    break;
            }
            super.deal(which, obj);
        }
    };

    private void httpGetUserInfo(String url) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, url, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    Gson gson = new Gson();
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            if (Errmsg.equals("未找到用户信息")) {
                                PreferenceUtils.setPrefString("user_id", "");
                                PreferenceUtils.setPrefString("account_type", "");
                                Intent intent = new Intent(getActivity(), LoginActivity.class);
                                intent.putExtra("tag", "2");
                                startActivity(intent);
                            }
                            return;
                        case 0:// 成功
                            UserInfoModel user_info = gson.fromJson(Response, UserInfoModel.class);
                            UserInfoModel.setUser_info(user_info);

                            service_name.setText(user_info.getReal_name());
                            ImageLoader.getInstance().displayImage(user_info.getHead_portrait(), center_img);
                            service_balance.setText("¥ " + user_info.getBalance());
                            httpGetpd_userlogin();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    private void httpGetpd_userlogin() {// 获取手机唯一标识
        TelephonyManager TelephonyMgr = (TelephonyManager) getActivity().getSystemService(Activity.TELEPHONY_SERVICE);
        String equipment = TelephonyMgr.getDeviceId();
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("equipment", equipment));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("equipment", equipment);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, Constant.Getpd_userlogin, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    Gson gson = new Gson();
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            if (Errmsg.equals("未找到用户信息")) {
                                PreferenceUtils.setPrefString("user_id", "");
                                PreferenceUtils.setPrefString("account_type", "");
                                Intent intent = new Intent(getActivity(), LoginActivity.class);
                                intent.putExtra("tag", "2");
                                startActivity(intent);
                            }
                            return;
                        case 0:// 成功
                            JSONObject js = new JSONObject(Response);
                            if ("1".equals(js.getString("status"))) {
//                                PreferenceUtils.setPrefString("user_id", "");
//                                PreferenceUtils.setPrefString("account_type", "");
                                Intent intent = new Intent(getActivity(), LoginActivity.class);
                                intent.putExtra("tag", "2");
                                startActivity(intent);
                            } else if ("2".equals(js.getString("status"))) {
                                httpGetmer_center_service_list();
                            }
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    private void httpGetmer_center_service_list() {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, Constant.Getmer_center_service_list, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String result = arg0.result.toString();
                List<ServiceFuwuModel> new_list = new ArrayList<ServiceFuwuModel>();
                try {
                    JSONObject json = new JSONObject(result);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    Gson gson = new Gson();
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            pullrefreshscrollview.onPullDownRefreshComplete();
                            pullrefreshscrollview.onPullUpRefreshComplete();
                            new_list = new ArrayList<ServiceFuwuModel>();
                            break;
                        case 0:// 成功
                            JSONObject js = new JSONObject(Response);
                            new_list = gson.fromJson(js.getString("list_dy"),
                                    new TypeToken<List<ServiceFuwuModel>>() {
                                    }.getType());
                            break;
                        case 2:// 暂无内容
                            pullrefreshscrollview.onPullDownRefreshComplete();
                            pullrefreshscrollview.onPullUpRefreshComplete();
                            new_list = new ArrayList<ServiceFuwuModel>();
                            break;
                    }
                    if (isFrist) {
                        if (isNullDate(new_list)) {
                            adapter.setList(new_list);
                            adapter.notifyDataSetChanged();
                        }
                        pullrefreshscrollview.onPullDownRefreshComplete();
                    } else {
                        List<ServiceFuwuModel> allList = adapter.getList();
                        allList.addAll(new_list);
                        adapter.setList(allList);
                        adapter.notifyDataSetChanged();
                        pullrefreshscrollview.onPullUpRefreshComplete();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    // 服务-服务商确认订单(服务商)
    private void httpGetmer_service_confirm_order(String order_no) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, Constant.Getmer_service_confirm_order, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            isFrist = true;
                            page = 1;
                            httpGetmer_center_service_list();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    // 服务-服务商确认订单(服务商)
    private void httpGetmer_service_update_order_amount(String order_no, String money) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        list.add(new NameValuePairSign("money", money));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("money", money);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, Constant.Getmer_service_update_order_amount, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            isFrist = true;
                            page = 1;
                            httpGetmer_center_service_list();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    // 服务-服务商确认完成服务(服务商)
    private void httpGetmer_service_complete_order(String order_no) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, Constant.Getmer_service_complete_order, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            isFrist = true;
                            page = 1;
                            httpGetmer_center_service_list();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    // 删除订单
    private void httpGetdel_order(String order_no) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, Constant.Getdel_order, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            isFrist = true;
                            page = 1;
                            httpGetmer_center_service_list();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    /**
     * @tab 判断listview是否有值
     */
    private boolean isNullDate(List<ServiceFuwuModel> rewordList) {
        if (rewordList == null || rewordList.size() == 0) {
            null_information_layout.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
            return false;
        } else {
            null_information_layout.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
            return true;
        }
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
        pullrefreshscrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        isFrist = true;
        page = 1;
        httpGetmer_center_service_list();
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
        pullrefreshscrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        isFrist = false;
        page++;
        httpGetmer_center_service_list();
    }
}
